package com.xiaobaibai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaobaibai.dao.BargainProductDao;
import com.xiaobaibai.entity.BargainProduct;
import com.xiaobaibai.entity.Product;
import com.xiaobaibai.service.IBargainProductService;
import com.xiaobaibai.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaobaibai
 * @since 2020-11-02
 */
@Service
public class BargainProductServiceImpl extends ServiceImpl<BargainProductDao, BargainProduct> implements IBargainProductService {

    @Autowired
    private IProductService productService;

    @Override
    @Cacheable(value = "bargain",key = "#root.methodName")
    public List<Product> getOkProduct() {
        QueryWrapper<BargainProduct> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("product_id");
        queryWrapper.eq("status",true);
        List<BargainProduct> list = this.list(queryWrapper);
        Set<Integer> set=list.stream().map(BargainProduct::getProductId).collect(Collectors.toSet());
        List<Product> products = productService.getBargainProduct(set);
        return products;
    }

}
